/**
 * 
 */
package com.swim.swimteach.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.swim.swimteach.entity.SwimTeach;
import com.swim.swimteach.service.SwimTeachService;

/**
 * 游泳教学Controller
 * @author 刘军武
 * @version 2021-05-17
 */
@Controller
@RequestMapping(value = "${adminPath}/swimteach/swimTeach")
public class SwimTeachController extends BaseController {

	@Autowired
	private SwimTeachService swimTeachService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public SwimTeach get(String id, boolean isNewRecord) {
		return swimTeachService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("swimteach:swimTeach:view")
	@RequestMapping(value = {"list", ""})
	public String list(SwimTeach swimTeach, Model model) {
		model.addAttribute("swimTeach", swimTeach);
		return "swim/swimteach/swimTeachList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<SwimTeach> listData(SwimTeach swimTeach, HttpServletRequest request, HttpServletResponse response) {
		Page<SwimTeach> page = swimTeachService.findPage(new Page<SwimTeach>(request, response), swimTeach); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("swimteach:swimTeach:view")
	@RequestMapping(value = "form")
	public String form(SwimTeach swimTeach, Model model) {
		model.addAttribute("swimTeach", swimTeach);
		return "swim/swimteach/swimTeachForm";
	}

	/**
	 * 保存游泳教学
	 */
	@RequiresPermissions("swimteach:swimTeach:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated SwimTeach swimTeach) {
		swimTeachService.save(swimTeach);
		return renderResult(Global.TRUE, text("保存游泳教学成功！"));
	}
	
	/**
	 * 删除游泳教学
	 */
	@RequiresPermissions("swimteach:swimTeach:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(SwimTeach swimTeach) {
		swimTeachService.delete(swimTeach);
		return renderResult(Global.TRUE, text("删除游泳教学成功！"));
	}
	
	/**
	 * 获取详情数据
	 */
	@RequestMapping(value = "detailsData")
	@ResponseBody
	public String detailsData(String swimTeachId) {
		return renderResult(Global.TRUE, text("获取详情数据成功！"), swimTeachService.get(swimTeachId));
	}
}